<template>
  <div>
    <div class="tabs">
      <div
        v-for="(item, index) in tabsData"
        :key="'tabs' + index"
        @click="selectTag(item)"
        :class="selectVal === item.value ? 'tab-box active' : 'tab-box'"
      >
        <div class="beforeBox"></div>
        <div class="before"></div>
        {{ item.name }}
        <div class="afterBox"></div>
        <div class="after"></div>
      </div>
      <slot name="headerRgt"></slot>
    </div>
    <div class="filterArea">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CustomTabs',
  props: {
    tabsData: {
      type: Array,
      default: function () {
        return [
          {
            name: '全部',
            value: 'all',
          },
          {
            name: '我的',
            value: '1',
          },
        ];
      },
    },
    selectVal: {
      type: String,
      default: '0',
    },
  },
  data() {
    return {};
  },
  methods: {
    selectTag(tab) {
      this.$emit('onChange', tab.value, tab);
    },
  },
};
</script>

<style lang="scss" scoped>
.tabs {
  display: flex;
  width: 100%;
  .tab-box {
    height: 52px;
    cursor: pointer;
    position: relative;
    text-align: center;
    line-height: 52px;
    padding: 0 13px;
    margin: 0 15px;
    font-size: 20px;
    font-weight: 600;
    color: $text-color-secondary;
    border-top: 2px solid rgba(0, 0, 0, 0);
    box-sizing: border-box;
  }
  .active {
    background: linear-gradient(180deg, #ebf3fe 0%, #ffffff 100%);
    border-top: 2px solid #fff;
    color: #121212;

    .beforeBox {
      position: absolute;
      top: -2px;
      left: -34px;
      height: 52px;
      width: 34px;
      z-index: 2;
      background: #fff;
      clip-path: path('M 0,52 C 17,52 17,0 34,0 L 34, 52 Z');
    }
    .before {
      position: absolute;
      top: 0px;
      left: -30px;
      height: 50px;
      width: 30px;
      z-index: 3;
      background: linear-gradient(180deg, #ebf3fe 0%, #ffffff 100%);
      clip-path: path('M 0,50 C 15,50 15,0 30,0 L 30, 50 Z');
    }
    .afterBox {
      position: absolute;
      top: -2px;
      right: -34px;
      height: 52px;
      width: 34px;
      z-index: 2;
      background: #fff;
      clip-path: path('M 0,0 C 17,0 17,52 34,52 L 0, 52 Z');
    }
    .after {
      position: absolute;
      top: 0;
      right: -30px;
      height: 100%;
      width: 30px;
      z-index: 3;
      background: linear-gradient(180deg, #ebf3fe 0%, #ffffff 100%);
      clip-path: path('M 0,0 C 15,0 15,50 30,50 L 0, 50 Z');
    }
  }
  .tab-box {
    &:first-child {
      border-left: 2px solid rgba(0, 0, 0, 0);
      padding: 0 13px 0 20px;
      margin-left: 0;
      .before,
      .beforeBox {
        display: none;
      }
    }
    &:last-child {
      border-right: 2px solid rgba(0, 0, 0, 0);
      padding: 0 20px 0 13px;
      margin-right: 0;
      .after,
      .afterBox {
        display: none;
      }
    }
  }
  .tab-box.active {
    &:first-child {
      border-left: 2px solid #fff;
      border-radius: 8px 0 0 0;
    }
    &:last-child {
      border-right: 2px solid #fff;
      border-radius: 0 8px 0 0;
    }
  }
}

.filterArea {
  width: 100%;
  // min-height: 192px;
  background: #fff;
  box-shadow: $box-shadow;
  border-radius: 0 8px 8px 8px;
  padding: 28px 20px 20px;
  box-sizing: border-box;
}
</style>
